#include <iostream>
#include <vector>
#include <algorithm>

bool cmp(std::pair<int, int> a, std::pair<int, int> b)
{
    if (a.second == b.second)
    {
        return a.first > b.first;
    }
    return a.second < b.second;
}

int main()
{
    int N;
    std::cin >> N;

    std::vector<std::pair<int, int>> tasks;
    for (int i = 0; i < N; i++)
    {
        int si, ei;
        std::cin >> si >> ei;
        tasks.push_back({si, ei});
    }

    std::sort(tasks.begin(), tasks.end(), cmp);

    int prev = tasks[0].second;
    int cnt = 1;
    int i = 1;
    while (i < tasks.size())
    {
        if (tasks[i].second > prev && tasks[i].first <= prev)
        {
            prev = tasks[i].second;
            cnt++;
        }
        i++;
    }
    std::cout << cnt << std::endl;
    return 0;
}